package com.wkh.datastructure.stack;
//判断括号
public class StackLeetOne {
    public static void main(String[] args) {
        String s = "([]){}";
        boolean flag = isValid(s);
        System.out.println(flag);
    }
    public static boolean isValid(String s){
        LinkedListStack<Character> stack = new LinkedListStack<>(s.length());
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '('){
                stack.push(')');
            }else if (s.charAt(i) == '['){
                stack.push(']');
            }else if (s.charAt(i) == '{'){
                stack.push('}');
            }else {
                if (stack.isEmpty() || stack.peek() != s.charAt(i)){
                    return false;
                }else {
                    stack.pop();
                }
            }
        }
        /*if (stack.isEmpty()){
            return true;
        }else {
            return false;
        }*/
        return stack.isEmpty();
    }
}
